package com.sikaryofficial.workbench.config.handler.impl;

import com.sikaryofficial.workbench.config.handler.BusinessCodeStrategy;
import org.apache.ibatis.reflection.MetaObject;

import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.Objects;

/**
 * @author : wuweihong
 * @desc : TODO  请填写你的功能描述
 * @date : 2024-09-30
 */

public class OrderItemCodeStrategy implements BusinessCodeStrategy {
    @Override
    public String generateCode(MetaObject metaObject) {
        String orderIdName = "orderItemId";
        String brandNoName = "brandNo";
        long orderIdValue = (long) metaObject.getValue(orderIdName);
        String brandNoValue = Objects.nonNull(metaObject.getValue(brandNoName)) ? (String) metaObject.getValue(brandNoName) : brandNoName;
        LocalDate localDate = LocalDate.now();
        int currYear = localDate.getYear();
        int currMonth = localDate.getMonthValue();
        DecimalFormat df = new DecimalFormat("00");
        return brandNoValue + "_" + currYear + "_" + df.format(currMonth) + "_" + orderIdValue;
    }
}
